package com.example.Controller;

import com.example.entity.Articles;
import com.example.entity.ArticlesLike;
import com.example.service.ArticlesService;
import com.example.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * The type Articles controller.
 *
 * @author XingGao
 */
@CrossOrigin //跨域
@RestController
@RequestMapping(value = "/articles")
public class ArticlesController {
    @Autowired
    private ArticlesService articlesService;

    /**
     * Gets board.
     *
     * @param articles the articles
     * @return the board
     */
    @PostMapping(value = "getArticles")
    public ResultData getBoard(@RequestBody Articles articles) {
        return articlesService.getBoard(articles);
    }

    /**
     * Gets board by name.
     *
     * @param articles the articles
     * @return the board by name
     */
    @PostMapping(value = "getArticlesByName")
    public ResultData getBoardByName(@RequestBody Articles articles) {
        return articlesService.getBoardByUser(articles);
    }

    /**
     * Gets label all.
     *
     * @return the label all
     */
    @PostMapping(value = "getArticlesLabel")
    public ResultData getLabelAll() {
        return articlesService.getLabelALL();
    }

    /**
     * Gets label.
     *
     * @param articles the articles
     * @return the label
     */
    @PostMapping(value = "getLabel")
    public ResultData getLabel(@RequestBody Articles articles) {
        return articlesService.getLabel(articles);
    }

    /**
     * Gets boardbyid.
     *
     * @param articles the articles
     * @return the boardbyid
     */
    @PostMapping(value = "getArticlesByid")
    public ResultData getBoardbyid(@RequestBody Articles articles) {
        return articlesService.getBoardbyid(articles);
    }

    /**
     * Add board result data.
     *
     * @param file     the file
     * @param articles the articles
     * @return the result data
     */
    @PostMapping(value = "addBoard")
    public ResultData addBoard(@RequestParam("file") MultipartFile file, Articles articles) {
        return articlesService.addBoard(file, articles);
    }

    /**
     * Delete byid result data.
     *
     * @param articles the articles
     * @return the result data
     */
    @PostMapping(value = "deleteByid")
    public ResultData deleteByid(@RequestBody Articles articles) {
        return articlesService.deleteByid(articles);
    }

    /**
     * Update articles result data.
     *
     * @param articles the articles
     * @param file     the file
     * @return the result data
     */
    @PostMapping(value = "updateByid")
    public ResultData updateArticles(Articles articles, @RequestParam("file") MultipartFile file) {
        return articlesService.updateArticles(articles, file);
    }

    /**
     * Add articles like result data.
     *
     * @param articlesLike the articles like
     * @return the result data
     */
    @PostMapping(value = "addArticlesLike")
    public ResultData addArticlesLike(@RequestBody ArticlesLike articlesLike) {
        return articlesService.addBoardLike(articlesLike);
    }

    /**
     * Del articles like result data.
     *
     * @param articlesLike the articles like
     * @return the result data
     */
    @PostMapping(value = "delArticlesLike")
    public ResultData DelArticlesLike(@RequestBody ArticlesLike articlesLike) {
        return articlesService.DelBoardLike(articlesLike);
    }

    /**
     * Board byuser result data.
     *
     * @param articlesLike the articles like
     * @return the result data
     */
    @PostMapping(value = "ArticlesLikeByUser")
    public ResultData BoardByuser(@RequestBody ArticlesLike articlesLike) {
        return articlesService.BoardByuser(articlesLike);
    }

    /**
     * Gets examine.
     *
     * @return the examine
     */
    @PostMapping(value = "getExamine")
    public ResultData getExamine() {
        return articlesService.getExamine();
    }

    /**
     * Sets examine.
     *
     * @param articles the articles
     * @return the examine
     */
    @PostMapping(value = "setExamine")
    public ResultData setExamine(@RequestBody Articles articles) {
        return articlesService.setExamineRow(articles);
    }

}

